package com.xia.qianke.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Repository;

/**
 * @ClassName CountDAO
 * @Description TODO
 * @Author XJY
 * @Date 2022/7/19 0:06
 * @Version 1.0
 **/
@Repository
public class CountDAO {
    @Autowired
    JdbcTemplate jdbcTemplate;

    //接口当日调用次数
    public void saveTimes(){
        String sql = "update t_time set sckd_time =sckd_time +1";
        jdbcTemplate.update(sql);
    }

    public Integer getTimes(){
        String sql = "select sckd_time from t_time";
        Integer count = jdbcTemplate.queryForObject (sql, Integer.class);
        return count;
    }

    //采用crontab的定时执行规则
    @Scheduled(cron = "0 0 0 * * *")
    public void clearTime(){
        String sql = "update t_time set sckd_time = 0";
        jdbcTemplate.update (sql);
    }
}
